package com.chen.controller;

import com.chen.dto.AccountA;
import com.chen.exception.MyRpcException;
import com.chen.service.BusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RequestMapping("/business")
@RestController
@Api(value = "业务测试",tags = "业务测试")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    /**
     * 模拟美元人民币互换
     * @param userId 用户id
     * @param rmb 人民币
     * @return
     */
    @PostMapping("/moneyConvert")
    @ApiOperation(value = "美元人民币兑换总程序入口")
    public String moneyConvert(int userId, BigDecimal rmb){
        BigDecimal dollar = rmb.divide(new BigDecimal(7));
        try {
            businessService.convert(userId,dollar,rmb);
        } catch (MyRpcException e) {
            e.printStackTrace();
            return "兑换失败："+e.getMessage();
        }
        return "兑换成功";
    }

}
